package com.sc.VenusQueryBeta.adapter;

import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sc.VenusQueryBeta.R;

import java.util.List;

/**
 * Created by Administrator on 8/10/2018.
 */

public class HotSearchGridAdapter extends BaseAdapter {
    private List<String> strings;
    private Context context;

    public HotSearchGridAdapter(Context context, List<String> strings) {

        this.context = context;
        this.strings = strings;
    }

    @Override
    public int getCount() {
        return strings.size();
    }

    @Override
    public Object getItem(int position) {
        return strings.get(position);
    }

    @Override
    public long getItemId(int position) {
        return  position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
       ViewHolder viewHolder;
            if (convertView == null){
                convertView = View.inflate(context, R.layout.item_hot_view,null);
                viewHolder = new ViewHolder(convertView);
                convertView.setTag(viewHolder);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    viewHolder.tvHotView.setText(strings.get(position));
                }

            }else {
                viewHolder= (ViewHolder) convertView.getTag();
            }
            return convertView;
    }
    class ViewHolder{
        TextView tvHotView;
        ViewHolder(View convertView) {
            tvHotView = convertView.findViewById(R.id.tv_hot_name);
        }
    }
}
